{include file='common/_meta' /}
<body>
<div class="container">

	<form class="layui-form" action="" lay-filter="" id="form-article">

		<div class="layui-row">
		 	<div class="layui-form-item layui-col-sm6">
		 	  	<label class="layui-form-label">渠道：</label>
		 	   	<div class="layui-input-block">
		 	     	<input type="text" placeholder="{$mode.company_name}"  class="layui-input" disabled>
		 	   	</div>
		 	 </div>
	 	 </div>

	 	 <div class="layui-row">
		 	<div class="layui-form-item layui-col-sm6">
		 	  	<label class="layui-form-label">余额：</label>
		 	   	<div class="layui-input-inline">
		 	     	<input type="text" placeholder="{$mode.balance} 条"  class="layui-input" disabled>
		 	   	</div>
                <div class="layui-form-mid strnum custom-color-red"></div>
		 	 </div>
	 	 </div>
		
		{if(session('role_id') != 38)}
        <div class="layui-row">
		 	<div class="layui-form-item layui-col-sm6">
		 	  	<label class="layui-form-label">单价：</label>
		 	   	<div class="layui-input-block">
		 	     	<input type="text" placeholder="{$mode.sms_price} 元/条"  class="layui-input" disabled>
		 	   	</div>
		 	 </div>
	 	</div>
		{/if}
		<div class="layui-row">
		  	<div class="layui-form-item layui-col-sm6">
		    	<label class="layui-form-label"><span class="custom-color-red">*</span>充值金额(元)：</label>
		    	<div class="layui-input-block">
			     	<input type="text" id="rechargenum" name="rechargenum" value="" placeholder="请输入充值金额" autocomplete="off" class="layui-input" onblur="sumduanxin(this)" onkeyup="sumduanxin(this)">
		    	</div>
		 	</div>
	 	</div>

		<div class="layui-row">
		  	<div class="layui-form-item layui-form-text layui-col-sm6">
		  	    <label class="layui-form-label">备注：</label>
		  	    <div class="layui-input-block">
		  	      	<textarea name="remarks" value="" placeholder="备注" class="layui-textarea" ></textarea>
		  	    </div>
		  	 </div>
	 	</div>

		<div class="layui-row">
		  	<div class="layui-form-item">
			    <div class="layui-input-block">
                    <input type="hidden" value="{$mode.channel_id}" name="channel_id" >
			    	<input type="hidden" value="{$mode.sms_price}" name="pricenum" class="pricenum">
			     	<button class="layui-btn custom-sm-fluid" lay-submit lay-filter="formDemo">提交</button>
			    </div>
		  	</div>
	  	</div>

	</form>

</div>
{include file="common/_footer"}

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
layui.use(['form', 'layer'], function() {

	var layer = layui.layer;
	var form  = layui.form;

	//监听提交
	form.on('submit(formDemo)', function(data) {

        layer.confirm('是否确认充值？', {
            btn: ['确认充值', '取消充值'] //可以无限个按钮
            ,yes: function(index, layero){

                var indexload = layer.load();

                $.ajax({
                    type : "POST",
                    url  : "{:url('Recharge/recharge_add')}",
                    data : $("#form-article").serialize(),
                    success : function(e) {

                        layer.close(indexload);

                        if(e != 'success') {
                            layer.msg(e,{icon: 5,time:3000});
                            return false;
                        }
                        layer.msg('充值成功',{icon:1,time:1000},function() {
                            layer.open({type: 3});parent.location.reload();
                        });
                    },
                    error : function(e){

                        layer.close(indexload);

                        layer.msg('提交错误',{icon: 5,time:3000});
                    }
                });

            }
        });

		return false;
	});

});

/*计算短信余额*/
function sumduanxin(obj) {
    var rechargenum = $("#rechargenum").val();
    var pricenum    = $(".pricenum").val();

    if(rechargenum == "" || pricenum == ""){
        $(".strnum").text("");
        return false;
    }

    IWS_CheckDecimal(obj);
    var strnum      = parseInt(parseFloat(rechargenum)/parseFloat(pricenum));

    $(".strnum").text("+"+strnum);
}

/*验证金额*/
function IWS_CheckDecimal(obj) {

    var temp = /^\d+\.?\d{0,3}$/;
    if (temp.test(obj.value)) {
    } else {
        obj.value = obj.value.substr(0, obj.value.length - 1);
        IWS_CheckDecimal(obj);
    }
}

</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>